package bennyhuo.generic;

import java.util.function.Supplier;

public class GenericTest1 {

    /**
     * 添加一个泛型约束实例1
     * @param a
     * @param b
     * @param <T>
     * @return
     */
    public static <T extends Comparable<T>> T maxOf1(T a, T b) {
        return a.compareTo(b) > 0 ? a : b;
    }


    /**
     * 多个泛型参数添加约束实例2
     * @param a
     * @param b
     * @param <T>
     * @param <R>
     * @return
     */
    public static <T extends Comparable<T> & Supplier<R>,
            R extends Number
            > R maxOf2(T a, T b) {
        return a.compareTo(b) > 0 ? a.get() : b.get();
    }

}
